<template>
	<om-addpage :busCode="busCode" style="padding-top: 35px;" menuName="个人信息调整" @formSubmit='formSubmit' :saveBtnText="submitBtnText"
	 :showHistoryBtn="true" historyBtnTop="60px" :resetBtnText="resetBtnText" @formReset='formReset'>
		<scroll-view scroll-x class="bg-white nav fixed">
			<view class="flex text-center">
				<view class="cu-item flex-sub " :class="index==TabCur?'text-green cur':''" v-for="(item,index) in 3" :key="index"
				 @tap="tabSelect" :data-index="index">
					<text v-if="index === 0">①信息录入</text>
					<text v-if="index === 1">………………</text>
					<text v-if="index === 2">②材料上传</text>
				</view>
			</view>
		</scroll-view>
		<view v-if="showTip" class="flex justify-center">
			<view class="bg-green light round padding-sm" style="position: fixed;z-index: 100;opacity:0.8;">
				温馨提示：带<text class="text-red">*</text>为必填项
			</view>
		</view>
		<view v-if="TabCur == 0">
			<om-white-space bgColor="#eee"></om-white-space>
			<om-sub title="个人信息">
				<uni-list>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="姓名" required></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<input v-model="formdata.infoname" name='infoname' placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="身份证件类别" required></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<picker @change="bindIdTypeChange" mode="selector" :value="idTypeIndex" :range="idTypeList" range-key="dicname">
									<view class="tui-right">{{ idTypeList.length && ~idTypeIndex ? idTypeList[idTypeIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="身份证号" required></om-label>
							</view>
							<view class=" tui-col-7">
								<input v-model="formdata.idCard" name='idCard' placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="民族" required></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<picker @change="bindNationChange" mode="selector" :value="nationIndex" :range="nationList" range-key="dicname">
									<view class="tui-right">{{ nationList.length && ~nationIndex ? nationList[nationIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="婚姻状况"></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<picker @change="bindMarriageChange" mode="selector" :value="marriageIndex" :range="marriageList" range-key="dicname">
									<view class="tui-right">{{ marriageList.length && ~marriageIndex ? marriageList[marriageIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="私人手机号码" required></om-label>
							</view>
							<view class=" tui-col-7">
								<input name='infophone' v-model="formdata.infophone" placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="私人手机短号"></om-label>
							</view>
							<view class="tui-col-7">
								<input v-model="formdata.shortNo" name='shortNo' placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="身高"></om-label>
							</view>
							<view class="tui-col-6">
								<input name='height' type="number" v-model="formdata.height" placeholder="请输入" />
							</view>
							<view class=" tui-col-1">
								<text>cm</text>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="政治面貌"></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<picker @change="bindPoliticalChange" mode="selector" :value="politicalIndex" :range="politicalList" range-key="dicname">
									<view class="tui-right">{{ politicalList.length && ~politicalIndex ? politicalList[politicalIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="外语语种"></om-label>
							</view>
							<view class=" tui-col-7">
								<input v-model="formdata.foreignLanguage" name='foreignLanguage' placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="外语水平"></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<input v-model="formdata.foreignLanguageLevel" name="foreignLanguageLevel" placeholder="请输入..." />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="私人邮箱"></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<input v-model="formdata.email" name="email" placeholder="请输入..." />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="私人QQ号码"></om-label>
							</view>
							<view class="tui-col-7">
								<input v-model="formdata.qq" name='qq' placeholder="请输入" />
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false" showClear @iconClear="bloodTypeClear">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="血型"></om-label>
							</view>
							<view class="tui-left tui-col-7">
								<picker @change="bindBloodTypeChange" mode="selector" :value="bloodTypeIndex" :range="bloodTypeList" range-key="dicname">
									<view class="tui-right">{{ bloodTypeList.length && ~bloodTypeIndex ? bloodTypeList[bloodTypeIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="户籍地址" required></om-label>
							</view>
							<view class="tui-right tui-col-7" @click="addressFunc">
								<view>{{ formdata.parentPlaceName || '请选择' }}</view>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="乡/镇/街道"></om-label>
							</view>
							<view class="tui-col-7"><input name="parentOthers" v-model="formdata.parentOthers" placeholder="请输入..." /></view>
						</view>
					</uni-list-item>
					<uni-list-item @iconClear="clearCurrentAddress" :showArrow="false" :showClear="true">
						<view class="tui-flex">
							<view class="tui-col-5" id="currentId">
								<om-label label="现居住地"></om-label>
							</view>
							<view class="tui-right tui-col-7" @click="currentAddressFunc">
								<view>{{ formdata.currentPlaceName || '请选择' }}</view>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item v-if="formdata.parentPlaceName && !formdata.currentPlaceName" :showArrow="false">
						<om-wing-blank class="flex justify-center">
							<view @click="sameAddrClick" class='cu-tag radius bg-grey'>同户籍地址</view>
						</om-wing-blank>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="乡/镇/街道"></om-label>
							</view>
							<view class="tui-col-7"><input name="currentOthers" v-model="formdata.currentOthers" placeholder="请输入..." /></view>
						</view>
					</uni-list-item>
				</uni-list>
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
			<om-sub title="其他相关信息">
				<uni-list>
					<uni-list-item :showArrow="false" :showClear="true" @iconClear="clearBank">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="工资卡发卡行"></om-label>
							</view>
							<view class="tui-col-7">
								<picker @change="bindSalaryBankChange" mode="selector" :value="salaryBankIndex" :range="salaryBankList"
								 range-key="dicname">
									<view class="tui-right">{{ salaryBankList.length && ~salaryBankIndex ? salaryBankList[salaryBankIndex].dicname : '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="发卡分支机构"></om-label>
							</view>
							<view class="tui-col-7"><input name="bankCardBranch" v-model="formdata.bankCardBranch" placeholder="请输入..." /></view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="户名"></om-label>
							</view>
							<view class="tui-col-7"><input name="bankCardName" v-model="formdata.bankCardName" placeholder="请输入..." /></view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="账号"></om-label>
							</view>
							<view class="tui-col-7"><input name="bankCard" v-model="formdata.bankCard" placeholder="请输入..." /></view>
						</view>
					</uni-list-item>
				</uni-list>
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
			<om-sub title="教育经历" subTitle="请从最高学历填起">
				<uni-list v-for="(item,index) in eduList" :key="index">
					<uni-list-item :showArrow="true" @click="openEdu(index)">
						<view>{{item.schoolE}}</view>
						<view class="text-gray text-sm padding-bottom-xs padding-top-xs">{{item.studyDirectEName ? (item.studyDirectEName+' | '+item.eduEName):item.eduEName}}</view>
						<view class="text-gray text-sm">{{item.startDateE+' 至 '+item.endDateE}}</view>
					</uni-list-item>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="openEdu()">增加教育经历</text>
				</view>
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
			<om-sub title="工作经历" subTitle="请从最近的工作经历填起,应届毕业生可不填">
				<uni-list v-for="(item,index) in workList" :key="index">
					<uni-list-item :showArrow="true" @click="openWork(index)">
						<view>{{item.orgNameW}}</view>
						<view class="text-gray text-sm padding-bottom-xs padding-top-xs">{{item.posNameW}}</view>
						<view class="text-gray text-sm">{{item.startDateW+' 至 '+item.endDateW}}</view>
					</uni-list-item>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="openWork()">增加工作经历</text>
				</view>
			</om-sub>

			<om-white-space bgColor="#eee"></om-white-space>
			<om-sub title="紧急联系人" subTitle="紧急情况下无法联系到您本人的备选联系人" required>
				<uni-list v-for="(item,index) in familyList" :key="index">
					<uni-list-item :showArrow="true" @click="openFamily(index)">
						<view>{{item.nameF + '('+item.appellationFName+')'}}</view>
						<view class="text-gray text-sm padding-bottom-xs padding-top-xs">{{item.mobileF}}</view>
					</uni-list-item>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="openFamily()">增加紧急联系人</text>
				</view>
			</om-sub>
		</view>
		<view v-else-if="TabCur == 2">
			<om-sub title="附件上传">
				<uni-list class="solid-top">
					<uni-list-item :showHover="false" :showArrow="false">
						<view class="tui-flex">
							<view class="tui-center tui-col-6 ">
								类别
							</view>
							<view class="tui-left tui-col-6 padding-left-xl">
								附件
							</view>
						</view>
					</uni-list-item>
					<view v-for="(item,index) in appendixList" :key="index">
						<uni-list-item :showHover="false" :showArrow="false" :showClear="true" :dataIndex="index" @iconClear="delAppendix(index)">
							<view class="tui-flex">
								<view class="tui-col-6 flex justify-center align-center">
									<picker class="appendix-upload" style="height: 100%;flex justify-center align-center" @change="bindCategoryChange"
									 :data-index="index" mode="selector" :value="item.appendixCateIndex" :range="categoryList" range-key="dicname">
										<view class="tui-center" style="height: 100%;">{{ categoryList.length && ~item.appendixCateIndex ? categoryList[item.appendixCateIndex].dicname : '请选择' }}</view>
									</picker>
								</view>
								<view class="tui-col-6 padding-top">
									<view class="cu-form-group">
										<view class="grid col-2 grid-square flex-sub">
											<view class="bg-img bg-img-2" v-for="(item2,index2) in item.tempFilelist" :key="index2" @tap="ViewImage(index,index2)">
												<image :src="getImageUrl(item2)" mode="aspectFit"></image>
												<view class="cu-tag bg-red" @tap.stop="DelImg(index,index2)">
													<text class='cuIcon-close'></text>
												</view>
											</view>
											<view class="solids" @tap="ChooseImage(index)" v-if="item.tempFilelist.length<2">
												<text class='cuIcon-cameraadd'></text>
											</view>
										</view>
									</view>
								</view>
							</view>
						</uni-list-item>
					</view>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="addUpload()">增加附件类别</text>
				</view>
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
	</om-addpage>
</template>

<script>
	const form = require("../../../static/js/formValidation.js")
	import {
		convertImgToBase64
	} from 'static/js/common.js'
	import { mapState, mapActions } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return {
				initLoadFlag:true,
				formdata: {
					infoname: '',
					idCard: '',
					idTypeId: '',
					idTypeName: '',
					nationCode: '',
					nationName: '',
					marriageCode: '',
					marriageName: '',
					infophone: '',
					height: '',
					politicalName: '',
					politicalId: '',
					foreignLanguage: '',
					foreignLanguageLevel: '',
					shortNo: '',
					email: '',
					qq: '',
					bloodTypeCode: '',
					bloodTypeName: '',
					salaryBankId: '',
					salaryBank: '',
					bankCardBranch: '',
					bankCardName: '',
					bankCard: '',
					currentStatusId: '',
					currentStatusName: '',
					parentPlaceId: '',
					parentPlaceName: '',
					parentOthers: '',
					currentPlaceId: '',
					currentPlaceName: '',
					currentOthers: '',
					eduStr: '',
					workStr: '',
					familyStr: '',
					busCode: 'RPS0201'
				},
				categoryList: [],
				appendixList: [], //附件
				submitBtnText: '下一步',
				resetBtnText: '',
				TabCur: 0,
				eduList: [], //教育经历
				familyList: [], //家庭成员
				workList: [], //工作经历
				idTypeIndex: -1,
				idTypeList: [],
				nationIndex: -1,
				nationList: [],
				marriageIndex: -1,
				marriageList: [],
				politicalIndex: -1,
				politicalList: [],
				currentStatusIndex: -1,
				currentStatusList: [],
				bloodTypeIndex: -1,
				bloodTypeList: [],
				salaryBankIndex: -1,
				salaryBankList: [],
				menuName: '个人信息调整',
				busCode: 'RPS0201',
				addressCacheKey: 'address-cache',
				currentAddressCacheKey: 'currentaddress-cache',
				eduCacheKey: 'register-edulist-cache',
				familyCacheKey: 'register-familylist-cache',
				workCacheKey: 'register-worklist-cache',
				showTip: true,
			};
		},
		computed: {
			...mapState(useLoginUserStore, ['orgId'])
		},
		methods: {
			tabSelect(e) {},
			sameAddrClick() {
				this.formdata.currentPlaceId = this.formdata.parentPlaceId
				this.formdata.currentPlaceName = this.formdata.parentPlaceName
				this.formdata.currentOthers = this.formdata.parentOthers
			},
			confirmSend() {
				this.hideSendModal()
				this.sendFunc()
			},
			delAppendix(index) {
				let appendix = this.appendixList[index]
				if (appendix) {
					let _that = this
					this.om.request("wxTpiAdjust/deleteCategory", {
						categoryId: appendix.appendixCateId,
						infophone: _that.formdata.infophone
					}, "post").then(res => {
						if (res.succeed) {
							_that.appendixList.splice(index, 1)
						}
					})
				}
			},
			getImageUrl(fileId) {
				return this.om.getUrl("wxTpiAdjust/getFile.do?fileId=" + fileId.toString())
			},
			ChooseImage(index) {
				let _that = this
				let appendix = _that.appendixList[index]
				if (!appendix.appendixCateId) {
					_that.om.toast("请先选择证件类别")
				} else {
					uni.chooseImage({
						count: 2, //默认9
						sizeType: ['original', 'compressed'],
						sourceType: ['album', 'camera'],
						success: (res) => {
							var appendix = _that.appendixList[index]
							_that.uploadImg(appendix, res.tempFilePaths, 0)
						}
					});
				}
			},
			uploadImg(appendix, tempFilePaths, i){
				let _that = this
				if(tempFilePaths && tempFilePaths.length > i ){
					var filePath = tempFilePaths[i]
					_that.om.uploadFile("wxTpiAdjust/uploadFile", filePath, null, {
						categoryId: appendix.appendixCateId
					}).then(d => {
						var json = JSON.parse(d)
						if (json.succeed) {
							if (json.value) {
								appendix.tempFilelist.push(json.value)
							} else {
								_that.om.toast("第"+(i+1)+"张图片上传失败，请重新上传")
							}
						} else {
							_that.om.toast(json.msg)
						}
						i++
						_that.uploadImg(appendix, tempFilePaths, i)
					})
				}
			},
			ViewImage(index, index2) {
				let _that = this
				var files = this.appendixList[index].tempFilelist.map(e => {
					return _that.getImageUrl(e)
				})
				uni.previewImage({
					urls: files,
					current: index2
				});
			},
			DelImg(index, index2) {
				let _that = this
				_that.om.request("wxTpiAdjust/deleteFile", {
					fileId: _that.appendixList[index].tempFilelist[index2]
				}, 'post').then(res => {
					if (res.succeed) {
						_that.appendixList[index].tempFilelist.splice(index2, 1)
					}
				})

			},
			addUpload() {
				this.appendixList.push({
					appendixCateIndex: -1,
					appendixCateId: "",
					appendixCateName: "",
					tempFilelist: [],
					fileDataList: []
				})
			},
			bloodTypeClear() {
				this.formdata.bloodTypeCode = ""
				this.formdata.bloodTypeName = ""
				this.bloodTypeIndex = -1
			},
			//血型
			bindBloodTypeChange(e) {
				if (e) {
					this.bloodTypeIndex = e.target.value;
				}
				if (~this.bloodTypeIndex && this.bloodTypeList.length) {
					this.formdata.bloodTypeCode = this.bloodTypeList[this.bloodTypeIndex].code
					this.formdata.bloodTypeName = this.bloodTypeList[this.bloodTypeIndex].dicname
				}
			},
			clearBank(){
				this.salaryBankIndex = -1
				this.formdata.salaryBank = ''
				this.formdata.salaryBankId = ''
			},
			bindSalaryBankChange(e) {
				if (e) {
					this.salaryBankIndex = e.target.value;
				}
				if (~this.salaryBankIndex && this.salaryBankList.length) {
					this.formdata.salaryBankId = this.salaryBankList[this.salaryBankIndex].id
					this.formdata.salaryBank = this.salaryBankList[this.salaryBankIndex].dicname
				}
			},
			/**
			 * 身份证类别
			 */
			bindIdTypeChange(e) {
				if (e) {
					this.idTypeIndex = e.target.value;
				}
				if (~this.idTypeIndex && this.idTypeList.length) {
					this.formdata.idTypeId = this.idTypeList[this.idTypeIndex].id
					this.formdata.idTypeName = this.idTypeList[this.idTypeIndex].dicname
				}
			},
			/**
			 * 民族
			 */
			bindNationChange(e) {
				if (e) {
					this.nationIndex = e.target.value;
				}
				if (~this.nationIndex && this.nationList.length) {
					this.formdata.nationCode = this.nationList[this.nationIndex].code
					this.formdata.nationName = this.nationList[this.nationIndex].dicname
				}
			},
			/**
			 * 婚姻
			 */
			bindMarriageChange(e) {
				if (e) {
					this.marriageIndex = e.target.value;
				}
				if (~this.marriageIndex && this.marriageList.length) {
					this.formdata.marriageCode = this.marriageList[this.marriageIndex].code
					this.formdata.marriageName = this.marriageList[this.marriageIndex].dicname
				}
			},
			/**
			 * 政治面貌
			 */
			bindPoliticalChange(e) {
				if (e) {
					this.politicalIndex = e.target.value;
				}
				if (~this.politicalIndex && this.politicalList.length) {
					this.formdata.politicalId = this.politicalList[this.politicalIndex].id
					this.formdata.politicalName = this.politicalList[this.politicalIndex].dicname
				}
			},
			/**
			 * 当前工作状态
			 */
			bindCurrentStatusChange(e) {
				if (e) {
					this.currentStatusIndex = e.target.value;
				}
				if (~this.currentStatusIndex && this.currentStatusList.length) {
					this.formdata.currentStatusId = this.currentStatusList[this.currentStatusIndex].id
					this.formdata.currentStatusName = this.currentStatusList[this.currentStatusIndex].dicname
				}
			},
			/**
			 * 类别选择
			 */
			bindCategoryChange(e) {
				let index = e.currentTarget.dataset.index
				if (!index) {
					index = 0
				}
				let appendixCateIndex = this.appendixList[index].appendixCateIndex
				if (e) {
					appendixCateIndex = e.target.value;
				}
				if (~appendixCateIndex) {
					let category = this.categoryList[appendixCateIndex]
					for (var i = 0; i < this.appendixList.length; i++) {
						if (this.appendixList[i].appendixCateId === category.id) {
							this.om.toast(category.dicname + "已上传")
							return
						}
					}
					this.appendixList[index].appendixCateIndex = appendixCateIndex
					this.appendixList[index].appendixCateId = category.id
					this.appendixList[index].appendixCateName = category.dicname
				}
			},

			addressFunc(e) {
				uni.navigateTo({
					url: '/pages/public/search/search?namefield=fullName&searchfield=q&cachename=' + this.addressCacheKey + "&url=" +
						encodeURIComponent("regions/getAddressCombox.do")
				});
			},
			clearCurrentAddress(){
				this.formdata.currentPlaceId = ''
				this.formdata.currentPlaceName = ''
				this.formdata.currentOthers = ''
			},
			currentAddressFunc(e) {
				uni.navigateTo({
					url: '/pages/public/search/search?namefield=fullName&searchfield=q&cachename=' + this.currentAddressCacheKey +
						"&url=" + encodeURIComponent("regions/getAddressCombox.do")
				});
			},
			openWork(index) { //编辑教育经历
				var url = 'work-exp?cachename=' + this.workCacheKey
				if (index != null && index != undefined) {
					url += '&index=' + index
				}
				uni.navigateTo({
					url: url
				});
			},
			openFamily(index) { //编辑教育经历
				var url = 'family-exp?cachename=' + this.familyCacheKey
				if (index != null && index != undefined) {
					url += '&index=' + index
				}
				uni.navigateTo({
					url: url
				});
			},
			openEdu(index) { //编辑教育经历
				var url = 'edu-exp?cachename=' + this.eduCacheKey
				if (index != null && index != undefined) {
					url += '&index=' + index
				}
				uni.navigateTo({
					url: url
				});
			},
			formSubmit: function() {
				let _that = this;
				let formdata = _that.formdata
				if (!formdata.infophone) {
					uni.redirectTo({
						url: "index"
					})
				}
				//表单规则
				let rules = [{
					name: "infoname",
					rule: ["required"],
					msg: ["请输入姓名"]
				}, {
					name: "idTypeId",
					rule: ["required"],
					msg: ["请选择身份证件类别"]
				}, {
					name: "idCard",
					rule: ["required"],
					msg: ["请输入身份证号"]
				}, {
					name: "nationCode",
					rule: ["required"],
					msg: ["请选择民族"]
				}, {
					name: "infophone",
					rule: ["required", "mobile"],
					msg: ["请输入私人手机号码", "请输入正确的私人手机号码"]
				}, {
					name: "parentPlaceId",
					rule: ["required"],
					msg: ["请选择户籍"]
				}, {
					name: "familyStr",
					rule: ["required"],
					msg: ["请至少添加一个紧急联系人"]
				}];
				let checkRes = form.validation(formdata, rules);
				if (!checkRes) {
					if (this.TabCur == 0) {
						_that.saveFunc()
					} else {
						_that.sendFunc()
					}
				} else {
					this.om.toast(checkRes);
				}

			},
			sendFunc() {
				let _that = this
				_that.om.request("wxTpiAdjust/doSend", {}, "post").then(res => {
					if (res.succeed) {
						_that.om.getFormInfo(res.value, _that.busCode);
					} else {
						_that.om.toast(res.msg)
					}
				})
			},
			saveFunc() {
				let _that = this
				var formdata = {}
				for(var i in _that.formdata){
					if(_that.formdata[i]){
						formdata[i] = _that.formdata[i]
					}
				}
				// console.log(formdata)
				_that.om.formSave('wxTpiAdjust/save', formdata, _that, function(id) {
					_that.TabCur = 2
					_that.submitBtnText = "发送"
					_that.resetBtnText = "上一步"
					_that.appendixList = []
					_that.om.request('wxTpiAdjust/getAppendixList').then(res=>{
						if(res.succeed){
							if(res.value.length){
								let objList = []
								res.value.forEach(e=>{
									var obj = {
										appendixCateId:e.appendixCateId,
										appendixCateName:e.appendixCateName,
										tempFilelist:e.tempFilelist
									}
									for(var i=0;i<_that.categoryList.length;i++){
										var cat = _that.categoryList[i]
										if(e.appendixCateId == cat.id){
											obj.appendixCateIndex = i
											break
										}
									}
									objList.push(obj)
								})
								_that.appendixList = objList
							}
						}
					})
				}, function(msg) {
					_that.om.toast(msg);
				})

			},
			formReset: function() {
				this.TabCur = 0
				this.submitBtnText = "下一步"
				this.resetBtnText = ""
			},
			initLaod() {
				let _that = this
				//民族
				_that.om.request('dictZero/getListByCode.do', {
					code: '20005'
				}).then(res => {
					//if (res instanceof Array) {
					if(Object.prototype.toString.call(res)==='[object Array]'){
						_that.nationList = res
						if(_that.formdata.nationCode){
							for(var i=0;i<_that.nationList.length;i++){
								var item = _that.nationList[i]
								if(item.code == _that.formdata.nationCode){
									_that.nationIndex = i
									break;
								}
							}
						}
					}
				});
				//婚姻
				_that.om.request('dictZero/getListByCode.do', {
					code: '23594'
				}).then(res => {
					//if (res instanceof Array) {
					if(Object.prototype.toString.call(res)==='[object Array]'){
						_that.marriageList = res
						if(_that.formdata.marriageCode){
							for(var i=0;i<_that.marriageList.length;i++){
								var item = _that.marriageList[i]
								if(item.code == _that.formdata.marriageCode){
									_that.marriageIndex = i
									break;
								}
							}
						}
					}
				});
				//血型
				_that.om.request('dictZero/getListByCode.do', {
					code: '37381'
				}).then(res => {
					//if (res instanceof Array) {
					if(Object.prototype.toString.call(res)==='[object Array]'){
						_that.bloodTypeList = res
						if(_that.formdata.bloodTypeCode){
							for(var i=0;i<_that.bloodTypeList.length;i++){
								var item = _that.bloodTypeList[i]
								if(item.code == _that.formdata.bloodTypeCode){
									_that.bloodTypeIndex = i
									break;
								}
							}
						}
					}
				});
				//身份证件类别
				_that.om.request('wxTpiApply/getListByCode', {
					code: '20007',
					'orgId': this.orgId
				}).then(res => {
					//if (res.value instanceof Array) {
					if(Object.prototype.toString.call(res.value)==='[object Array]'){
						_that.idTypeList = res.value
						if(_that.formdata.idTypeId){
							for(var i=0;i<_that.idTypeList.length;i++){
								var item = _that.idTypeList[i]
								if(item.id == _that.formdata.idTypeId){
									_that.idTypeIndex = i
									break;
								}
							}
						}
					}
				});
				//政治面貌
				_that.om.request('wxTpiApply/getListByCode.do', {
					code: '20010',
					'orgId': this.orgId
				}).then(res => {
					//if (res.value instanceof Array) {
					if(Object.prototype.toString.call(res.value)==='[object Array]'){
						_that.politicalList = res.value
						if(_that.formdata.politicalId){
							for(var i=0;i<_that.politicalList.length;i++){
								var item = _that.politicalList[i]
								if(item.id == _that.formdata.politicalId){
									_that.politicalIndex = i
									break;
								}
							}
						}
					}
				});
				//应聘人员目前状态
				_that.om.request('wxTpiApply/getListByCode.do', {
					code: '23586',
					'orgId': this.orgId
				}).then(res => {
					//if (res.value instanceof Array) {
					if(Object.prototype.toString.call(res.value)==='[object Array]'){
						_that.currentStatusList = res.value
						if(_that.formdata.currentStatusId){
							for(var i=0;i<_that.currentStatusList.length;i++){
								var item = _that.currentStatusList[i]
								if(item.id == _that.formdata.currentStatusId){
									_that.currentStatusIndex = i
									break;
								}
							}
						}
					}
				});
				_that.om.request('wxTpiApply/getListByCode.do', {
					code: '35872',
					'orgId': this.orgId
				}).then(res => {
					//if (res.value instanceof Array) {
					if(Object.prototype.toString.call(res.value)==='[object Array]'){
						_that.salaryBankList = res.value
						if(_that.formdata.salaryBankId){
							for(var i=0;i<_that.salaryBankList.length;i++){
								var item = _that.salaryBankList[i]
								if(item.id == _that.formdata.salaryBankId){
									_that.salaryBankIndex = i
									break;
								}
							}
						}
					}
				});
				//附件类别
				_that.om.request('wxTpiApply/getListByCode.do', {
					code: '38392',
					'orgId': this.orgId
				}).then(res => {
					//if (res.value instanceof Array) {
					if(Object.prototype.toString.call(res.value)==='[object Array]'){
						_that.categoryList = res.value
					}
				});
			},
			loadCache() {
				let _that = this
				uni.getStorage({
					key: _that.addressCacheKey,
					success: function(res) {
						_that.formdata.parentPlaceName = res.data.fullName;
						_that.formdata.parentPlaceId = res.data.id;
						uni.removeStorage({
							key: _that.addressCacheKey
						});
					}
				});
				uni.getStorage({
					key: _that.currentAddressCacheKey,
					success: function(res) {
						_that.formdata.currentPlaceName = res.data.fullName;
						_that.formdata.currentPlaceId = res.data.id;
						uni.removeStorage({
							key: _that.currentAddressCacheKey
						});
					}
				});
				uni.getStorage({
					key: _that.eduCacheKey,
					success: function(res) {
						_that.eduList = res.data;
						if (_that.eduList && _that.eduList.length) {
							_that.formdata.eduStr = JSON.stringify(_that.eduList)
						}else{
							_that.formdata.eduStr = ""
						}
					}
				});
				uni.getStorage({
					key: _that.familyCacheKey,
					success: function(res) {
						_that.familyList = res.data;
						if (_that.familyList && _that.familyList.length) {
							_that.formdata.familyStr = JSON.stringify(_that.familyList)
						}else{
							_that.formdata.familyStr = ""
						}
					}
				});
				uni.getStorage({
					key: _that.workCacheKey,
					success: function(res) {
						_that.workList = res.data;
						if (_that.workList && _that.workList.length) {
							_that.formdata.workStr = JSON.stringify(_that.workList)
						}else{
							_that.formdata.workStr = ""
						}
					}
				});
			},
			setCache(){
				let _that = this
				uni.setStorage({
					key: _that.eduCacheKey,
					data:_that.eduList
				});
				uni.setStorage({
					key: _that.familyCacheKey,
					data:_that.familyList
				});
				uni.setStorage({
					key: _that.workCacheKey,
					data:_that.workList
				});
				this.loadCache()
			},
			loadForm() {
				let _that = this
				this.om.request("wxTpiAdjust/getInfo").then(res=>{
					if(res.succeed){
						let tpiAdjust = res.value.tpiAdjust
						_that.formdata = tpiAdjust
						_that.formdata.parentPlaceId = tpiAdjust.parentCountyId || tpiAdjust.parentCityId || tpiAdjust.parentProvinceId
						let parentPlaceName = ''
						if(tpiAdjust.parentProvinceName){
							parentPlaceName+=tpiAdjust.parentProvinceName
						}
						if(tpiAdjust.parentCityName){
							parentPlaceName+= " / " + tpiAdjust.parentCityName
						}
						if(tpiAdjust.parentCountyName){
							parentPlaceName+= " / " + tpiAdjust.parentCountyName
						}
						_that.formdata.parentPlaceName = parentPlaceName
						_that.eduList =  res.value.eduList
						_that.familyList =  res.value.familyList
						_that.workList =  res.value.workList
						_that.setCache()
						_that.initLaod()
					}else{
						_that.setCache()
						_that.om.toast(res.msg,5000)
					}
				})
			}
		},
		onLoad: function(options) {
			let _that = this
			uni.setNavigationBarTitle({
				title: _that.menuName
			});
			setTimeout(function() {
				_that.showTip = false
			}, 10000);
			this.initLoadFlag = true
			this.loadForm()
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.saveFlag = false;
			if(!this.initLoadFlag){
				this.loadCache()
			}else{
				this.initLoadFlag = false
			}
		},
	};
</script>

<style>
	.showimg {
		border: 4upx solid #e9e9e9;
		overflow: hidden;
		width: 90%;
		margin: 0 auto;
		background: #eee;
		height: 350upx;
		margin-top: 40upx;
		align-items: center;
		justify-content: center;
	}

	.showimg>image {
		width: 100%;
		height: 100%;
	}

	.showimg>text {
		font-size: 40upx;
		color: #888;
	}

	.appendix-upload {
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bg-img-2 {
		width: 80%;
		height: 80%;
		position: absolute;
	}
</style>
